package top.kaoshanji.p1ch02b;

import java.lang.reflect.Proxy;

/**
 * author kaoshanji
 * ^_^
 * create time 2024/12/23 21:02
 */
public class GreetFactory {

    // 参数是 GreetV1 的一个实现类
    // 返回类型是 GreetV2 的代理对象
    public static GreetV2 adaptGreet(GreetV1 greet) {

        GreetAdapter adapter = new GreetAdapter(greet);
        ClassLoader cl = greet.getClass().getClassLoader();
        return (GreetV2) Proxy.newProxyInstance(cl, new Class<?>[]{GreetV2.class}, adapter);

    }

}
